package com.account.manager.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AccessFilter implements Filter {
	
	private Logger logger=LoggerFactory.getLogger(AccessFilter.class);
	
	@Override
	public void destroy() {
		
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        // 打印请求路径
        String reqUri = httpServletRequest.getRequestURI();
        String qs =
                httpServletRequest.getQueryString() == null ? "" : httpServletRequest
                        .getQueryString();
        logger.info("{} {} {} {}", httpServletRequest.getRemoteAddr(), httpServletRequest.getMethod(),
                reqUri, qs);
        
        chain.doFilter(request, response);
		
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
		
	}

}
